<<<<<<< .mine
% clear all;
% close all;
%  
cd ~/cvx;
=======
 clear all;
 close all;
 
 cd ~/cvx;
cvx_setup;
cd ~/CS348A/landscape-tour/ym/code_local;

%given data
d=1;
triangleFile='../finalData/hw4.edges';
tourFile='../finalData/hw4.tour';
outputFile='../sequence.txt';

%to do...
[sites, edges, triangles]=readTriangles(triangleFile);
siteGrid=createSiteGrid(sites);
triangleGrid=createTriangleGrid(sites,triangles);
[tour]=readTour(tourFile);

% find delta_min (minimum distance to terrain)
delta_min=findDelta(sites, tour)-d;
sites(:,3)=sites(:,3)+delta_min;

%find a initial guess
[X, Y]=findInitialSequence(tour, d);
numTours=size(tour,1);
for t=1:(numTours-1)
    tour2=tour(t+1,:)';
    guess=Y((3*t-2):(3*t));
    if t==1
        prev=[];
        tour1=tour(t,:)';
    else
        prev_idx=size(localSequence,2);
        prev=localSequence(:,prev_idx);
        tour1=localSequence(:,(prev_idx-1));
    end
    after=[]; %no constraint given
    localSequence=findLocalSequence(prev, tour1, guess, tour2, after, ...
        d,sites, triangles, triangleGrid);
    if t==1
        totalSequence=localSequence(:,1:(end-1));
    else
        totalSequence=[totalSequence, localSequence(:,3:(end-1))];
    end
    drawTrajectory(2,totalSequence,sites);
end

totalSequence=[totalSequence, localSequence(:,end)];
drawTrajectory(3,totalSequence, sites);
writeOutput(outputFile, totalSequence);
